package com.cvmars.jianyou.module.adapter;

import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.cvmars.jianyou.R;
import com.cvmars.jianyou.config.MyConfig;
import com.cvmars.jianyou.model.UserModel;
import com.cvmars.jianyou.module.activity.PersonHomeActivity;
import com.cvmars.jianyou.module.activity.XiangQinDetailActivity;
import com.cvmars.jianyou.module.activity.XiangQingActivity;
import com.cvmars.jianyou.utils.ImageUtils;
import com.cvmars.jianyou.utils.ToastUtils;
import com.moxun.tagcloudlib.view.TagsAdapter;
import com.orhanobut.hawk.Hawk;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hehaifeng on 2018/12/29.
 */

public class VectorTagsAdapter extends TagsAdapter {

    List<UserModel> list;

    Context mContext;

    public VectorTagsAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setList(List<UserModel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public View getView(Context context, final int position, ViewGroup parent) {

        View view = LayoutInflater.from(context).inflate(R.layout.tag_item_vector, parent, false);
        ImageView imageView = (ImageView) view.findViewById(R.id.vector_img);
        ImageUtils.loadImage(mContext, list.get(position).avatar_url, imageView);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                UserModel model = Hawk.get(MyConfig.SP_CACHE_USERMODEL);

                if (model.is_rut) {
                    onGoHome(list.get(position));
                } else {
                    ToastUtils.show("请修改资料，提交信息");
                }
            }
        });
        return view;
    }


    private void onGoHome(UserModel id) {


        Intent intent = new Intent(mContext,
                XiangQinDetailActivity.class);
        intent.putExtra("user", id);
        mContext.startActivity(intent);

    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getPopularity(int position) {
        return position % 5;
    }

    @Override
    public void onThemeColorChanged(View view, int themeColor) {


    }

}
